// class Greeter {
//     greeting: string;
//     greeting2:number;
//     constructor(message: string,num: number) {
//         this.greeting = message;
//         this.greeting2 = num;
//     }

//     greet() {
//         return "Hello, " + this.greeting + this.greeting2;
//     }
// }


// let greeter = new Greeter("world",123);
// //console.log(greeter.greet());

// let test1:number = 123;
// let test2:string = '111';
// test1 += 1;
// //console.log(test1);


// function fn(num:number):number{
//     return 123 * num;
// }





// class Parent {
//     greeting: string;
//     greeting2:number;
//     constructor(message: string,num: number) {
//         this.greeting = message;
//         this.greeting2 = num;
//     }

//     greet() {
//         return "Hello, " + this.greeting + this.greeting2;
//     }
// }

// class Child extends Parent{
//     greeting3:boolean = false;
//     // constructor(greeting: string,greeting2:number){
//     //     super(greeting,greeting2);
//     // }

//     getData():string{
//         console.log(this.greeting);
//         console.log(this.greeting2);
//         return this.greeting + this.greeting2;
//     }
// }

// let child = new Child('string',123);
// // console.log(child.greeting3);
// //console.log(child.getData());



let arr1:Array<string> = ['11'];
let arr2:Array<number> = [111];
let arr3:[string,number] = ['111',11];
enum arr4Enum{
    data1, //0
    data2, //1
    data3  //2
}
let arr4:arr4Enum = arr4Enum.data1; //获取索引

function fn1():number{
    return 123
}
function fn2():string{
    return '123';
}
function fn3():void{
    console.log('fn3');
}
function fn4(number1:string,number2:string):string{
    return number1 + number2;
}
//函数类型
let fnType : (a:number,b:number)=>number;

let dataobj1:{name:string,age:number} = {
    name:'小陈',
    age:22
};
type dataObj2Type = {names:string[],fn1:(item:string) => string[]};  //类型赋值
let dataobj2: dataObj2Type = {
    names:['名称1'],
    fn1:function(item:string):string[]{
        this.names.push(item)
        return this.names;
    }
}
// console.log(dataobj2.fn1('test'),'dataobj2');
let unionType: number | string | boolean;  //多种类型赋值

//never
let never:never; 
//不能将其他类型转化为never类型
// never = 111;
//never一般用于抛出异常
function throwErrer(msg:string) :never{
    throw new Error(msg);
}
// console.log(throwErrer('抛出异常'))
//never 死循环
function loop():never{
    while(true){}
}
//练习
interface sumValueType{  //规则
   money:number,
   count:(value:number)=>void
}
let sumValue:sumValueType = {
    money:20,
    count(value:number):void{
        this.money = value;
    }
}

let handleCount:{name:string,sumValue:sumValueType,friends:string[]} = {
    name:'Henry',
    sumValue:sumValue,
    friends:['bucky','elyse']
}

//类
class Person{
    //public 公开  private 私有 只能在本类访问   protected只能在本类和子类访问
    public name:string = '名称';  //初始化
    private _age:number = 22;  //初始化
    protected sex:string = '男'; //初始化

    constructor(name:string,sex:string){  //构造函数 实例化自动触发
      this.name = name;
      this.sex = sex;
    }

    set setAge(value:number){ //私有属性赋值 set
      this._age = value;
    }

    get getAge(){  //私有属性取值 get
       return this._age;
    }

    static username:string = '用户名称';  //静态属性

}

// let person = new Person('新名称',33,'女');
// console.log(person.name);
//继承
class Student extends Person{
   studentId:number = 123;
   constructor(name:string,sex:string){
      super(name,sex); //继承父类
      //console.log(this.studentId);
   }
}
// let student = new Student('新名称','女');
// console.log(student.getAge);
// console.log(Student.username,'测试静态属性');


//interface各种常用参数
interface interfaceType{  //规则
   username?:string,   //可选
   sex:string,   //必传
   readonly salary :number,  //只读
   [propName:string]:any, //任何string名字
   funtion1(): void //定义一个函数
}
let interfaceObj:interfaceType = {
   username:'用户名',
   sex:'男',
   salary:7000,
   randomStr:'111',
   funtion1:function(){
      console.log('函数');
   }
}
interface interfaceType2{  //规则
   id:number
}
//implements实现
class InterfaceClass implements interfaceType,interfaceType2{ //继承接口
   username  = '用户名';
   sex = '男';
   salary = 7000;
   randomStr = '111';
   funtion1 = function(){
      console.log('函数');
   };
   id = 12;

   constructor(){
      
   }
}
class InterfaceClassChild extends InterfaceClass{
   data1:string;
   data2:string;
   constructor(data1:string,data2:string){
      super(); //继承父类
      this.data1 = data1;
      this.data2 = data2;
   }

   get_a_and_b_data() : string{
      return this.data1 + '|' + this.data2;
   }

}
// let interfaceClassChild = new InterfaceClassChild('data1','data2');
// console.log(interfaceClassChild.get_a_and_b_data());

//泛型 根据入参变成相对应的类型
function identify1<T>(age:T):T {
   return age;
}
//指定类型
//console.log(identify1<string>('121aaa3'));
//自定义
//console.log(identify1(111));

interface interfaceIdentifyType{  //规则
   <T>(age:T):T
}

function identify2<T extends number>(num:T):any {
   return num;
}
//console.log(identify2(1)); //只能传number

function identify3<T extends {length : any}>(obj:T):any {
   return obj;
}
//console.log(identify3({length:123})); //必须有个对象 里面有个length

class CountNumber<T> {
   number1 :T;
   number2 :T;

   constructor(num1:T,num2:T){
      this.number1 = num1;
      this.number2 = num2;
   }

   calcalate():number{
      // return this.number1 + this.number2;
      return (+this.number1) + (+this.number2); //因为泛型不能相乘 所以强加上+号 ts添加 
   }
}

let countNumber = new CountNumber(10,20);
// console.log(countNumber.calcalate());

function buildName(x: string, y: string) {
   return x + y; 
};
console.log(buildName('Bob','Adams'));

// interface Square {
//    kind: "square";
//    size: number;
// }

interface Animal  {
   kind:  string;
   size: number;
}

function createZoo(): Animal {
   return {
      kind:'111',
      size:111
   }
}
